<template>
	<view class="inner pt30">
        <view v-if="infoData.title" class="mb20">{{infoData.title}}</view>
        <view v-else class="tc gray f26 pt10">加载中...</view>
        <view v-if="infoData.updated" class="mb20 f24">{{new Date(infoData.updated).format()}}</view>
        <view v-if="infoData.body" class="f28">{{infoData.body}}</view>
        <view v-if="doc" class="f28 mt15 text-wrap">{{doc}}</view>
	</view>
</template>

<script>
	import swiperPage from '@/components/mo-swiper-list/swiper-page.vue'
	import { mapActions, mapState } from 'vuex'
    import { staticURL, getBookInfo, getMixAtoc, getChapter,getABtoc } from '@/api'
    import { pretty, 
        decrypt,
        aesGcmDecrypt } from '@/utils'
console.log(418,decrypt)
console.log(419,aesGcmDecrypt)

	export default {
		components: {
			swiperPage
		},
		data() {
			return {
                infoData: {},
				params: {
					bookid: ""
				},
                doc:''
			}
		},
		computed:{
			...mapState('novel', ['userInfo']),
		},
		onLoad(option){
            this.params.bookid = option.id;
			const eventChannel = this.getOpenerEventChannel()
			let _this = this
			eventChannel.on('acceptData', function(data) {
				_this.params = data
                _this.getInfo()
			})
		},
		onShow(){
			
		},
		methods: {
			...mapActions('novel',['getStatistics', 'getGender']),
            async getInfo(){
                let t = new Date().getTime() + ''
                const params = { 
                    k: this.params.id,
                    t: t.slice(0,10),
                    link: encodeURIComponent(this.params.link),
                    // link: 'http%3a%2f%2fbook.my716.com%2fgetBooks.aspx%3fmethod%3dcontent%26bookId%3d1127281%26chapterFile%3dU_1212539_201701211420571844_4093_2.txt'
                }
                const res = await getChapter(params)
                res.cover = staticURL + res.cover
                // #ifdef MP-WEIXIN
                res.cover =  'https:' + res.cover
                // #endif
                this.infoData = res.chapter

                this.doc = res.chapter.cpContent ? pretty(res.chapter.cpContent) : ''
                console.log(63,res)
                const key = "Giwy0RlT4njH0hw593d6jRNfixijfDXaTNVaF/DHmnfUJ1Vj6QG8eL+nXiuHJ55jVexxuA=="
                const chapterBought = this.getBoughtChapterKey(res.chapter.order,[1,2,3,4,5])
                console.log(64,chapterBought)
                // console.log(65,aesGcmDecrypt(key))
                // console.log(67,decrypt(res.chapter.cpContent,key))
            },
            getBoughtChapterKey(chapterOrder, boughtChapters) {
                var key = null;
                for (var i = 0; i < boughtChapters.length; i++) {
                    if (boughtChapters[i].order === chapterOrder) {
                        key = boughtChapters[i].key;
                    }
                }
                return key;
            }
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #fff;
	}
	.books-pic{
		width: 180rpx;
		.pic{
			width: 100%;
			border-radius: 10rpx;
		}
	}
    .site{
        display: inline-block;
        font-size: 24rpx;
        padding: 10rpx 20rpx;
        margin-top: 30rpx;
        color: #d6966a;
        background-color: #ffe7d7;
        border-radius: 50rpx 50rpx;
    }
    .cgty{
        display: inline-block;
        font-size: 24rpx;
        padding: 10rpx 20rpx;
        margin-top: 30rpx;
        color: #999;
        background-color: #f5f5f5;
        border-radius: 50rpx 50rpx;
    }
    .start{
        display: inline-block;
        font-size: 28rpx;
        padding: 10rpx 30rpx;
        margin-top: 30rpx;
        background-color: #f5f5f5;
        border-radius: 50rpx 50rpx;
        &.go{
            color: #fff;
            background-color: $theme-color;
        }
        &.add{
            border: 1px solid $theme-color;
            color: $theme-color;
            background-color: transparent;
        }
    }
    .text-wrap{
        word-wrap: break-word; 
        word-break: break-all; 
        text-align: justify;
    }
	
</style>
